package com.yuexun.dhdoctor.module.mythings.ui;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.TextView;


import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.base.BaseKJActivity;
import com.yuexun.dhdoctor.baselistener.OnRecorderListener;
import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.module.Contract.bean.ChildDepartmentsBean;
import com.yuexun.dhdoctor.module.Contract.bean.GroupGroupData;
import com.yuexun.dhdoctor.module.Contract.bean.People;
import com.yuexun.dhdoctor.module.commun.ui.Act_Choice_Member;
import com.yuexun.dhdoctor.module.commun.ui.Act_Department;
import com.yuexun.dhdoctor.module.commun.ui.Act_Group;
import com.yuexun.dhdoctor.module.email.adapter.MailFileAdapter;
import com.yuexun.dhdoctor.module.email.bean.MailFileDataBean;
import com.yuexun.dhdoctor.module.email.bean.UploadBean;
import com.yuexun.dhdoctor.module.email.model.impl.UploadModel;
import com.yuexun.dhdoctor.module.email.presenter.IUploadPresenter;
import com.yuexun.dhdoctor.module.email.presenter.impl.UploadPresenter;
import com.yuexun.dhdoctor.module.email.ui.view.IUploadView;
import com.yuexun.dhdoctor.module.mythings.bean.BackMemberData;
import com.yuexun.dhdoctor.module.mythings.bean.FeedBackResultBean;
import com.yuexun.dhdoctor.module.mythings.bean.FlowMemberData;
import com.yuexun.dhdoctor.module.mythings.bean.SignDtlData;
import com.yuexun.dhdoctor.module.mythings.bean.TaskMainBean;
import com.yuexun.dhdoctor.module.mythings.bean.WhiteBean;
import com.yuexun.dhdoctor.module.mythings.bean.WhiteData;
import com.yuexun.dhdoctor.module.mythings.model.impl.ThingModel;
import com.yuexun.dhdoctor.module.mythings.presenter.impl.FeedBackPresenter;
import com.yuexun.dhdoctor.module.mythings.presenter.impl.FlowPresenter;
import com.yuexun.dhdoctor.module.mythings.presenter.impl.SignDtlPresenter;
import com.yuexun.dhdoctor.module.mythings.ui.view.IFeedBackView;
import com.yuexun.dhdoctor.module.mythings.ui.view.IFlowView;
import com.yuexun.dhdoctor.module.mythings.ui.view.ISignDtlView;
import com.yuexun.dhdoctor.util.CommonUtil;
import com.yuexun.dhdoctor.util.GetPathFromUri4kitkat;
import com.yuexun.dhdoctor.util.VoicePlayUtil;
import com.yuexun.dhdoctor.widget.ActionSheetDialog;
import com.yuexun.dhdoctor.widget.DoubleSureDialog;
import com.yuexun.dhdoctor.widget.FixedSwipeListView;
import com.yuexun.dhdoctor.widget.ToastDialog;
import com.yuexun.dhdoctor.widget.UploadDialog;
import com.yuexun.dhdoctor.widget.ViewShowDialog;
import com.yuexun.dhdoctor.widget.VoiceDialog;
import com.yuexun.dhdoctor.widget.WriteDialog;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by work-jx on 2016/7/28.
 */
public class Act_ThingsFeedback extends BaseKJActivity implements IFeedBackView, IUploadView, IFlowView, ISignDtlView {

    @Bind(R.id.tv_feedback_result)
    TextView tvFeedbackResult;
    @Bind(R.id.tv_feedback_sign)
    TextView tvFeedbackSign;
    @Bind(R.id.et_content)
    EditText etComment;
    @Bind(R.id.et_higher)
    TextView etHigher;
    @Bind(R.id.keyboard_redio)
    RadioButton keyboardRedio;
    @Bind(R.id.write_redio)
    RadioButton writeRedio;
    @Bind(R.id.voice_redio)
    RadioButton voiceRedio;
    @Bind(R.id.ic_voice_show)
    LinearLayout icVoiceShow;
    @Bind(R.id.progressBar)
    ProgressBar progressBar;
    @Bind(R.id.ic_txt_view)
    LinearLayout icTxtView;
    @Bind(R.id.write_delete)
    ImageView writeDelete;
    @Bind(R.id.ic_write_show)
    LinearLayout icWriteShow;
    @Bind(R.id.voice_time)
    TextView voiceTime;
    @Bind(R.id.voice_first)
    ImageView voiceFirst;
    @Bind(R.id.voice_secend)
    ImageView voiceSecend;
    @Bind(R.id.iv_add_member)
    ImageView ivAddMember;
    @Bind(R.id.person_view)
    LinearLayout personView;
    @Bind(R.id.select_txt)
    TextView selectTxt;
    @Bind(R.id.departorpeople)
    TextView departorpeopletxt;
    @Bind(R.id.select_depart)
    LinearLayout selectDepart;
    @Bind(R.id.copy_me_et_person)
    TextView copyMeEtPerson;
    @Bind(R.id.cope_me_ll)
    LinearLayout copeMeLl;
    @Bind(R.id.flv_attachment)
    FixedSwipeListView flvAttachment;
    @Bind(R.id.ll_extra_file)
    LinearLayout llExtraFile;

    List<SignDtlData> signDtlDatas = new ArrayList<>();
    ArrayList<People> usersBeans_origin = new ArrayList<People>();
    ArrayList<ChildDepartmentsBean> departmentBeans = new ArrayList<ChildDepartmentsBean>();
    //选取群组list
    ArrayList<GroupGroupData> groupGroupData = new ArrayList<>();
    ArrayList<People> usersBeans_origin_copy = new ArrayList<>(); //抄送

    TaskMainBean taskMainBean = new TaskMainBean();
    private String taskid;
    private String configid;
    private String dtlId;
    String accountId;
    SignDtlPresenter signDtlPresenter;
    FeedBackPresenter presenter;
    FlowPresenter flowPresenter;
    boolean isSent = false; //流转判断
    FlowMemberData memberData;

    //1 部门  2 个人 3 群组
    private int choose = 2;

    //语音
    private VoiceDialog voiceDialog;
    private File recorderFile;
    private String rFileUrl;
    private int voicetime;//语音时长
    //播放按钮的播放或者停止标志位  0为没有播放，1为开始播放，2为停止播放
    private int goOrPause = 0;
    private VoicePlayUtil playUtil;

    //手写
    private ViewShowDialog viewDialog;
    private File writeFile;
    private String wFileUrl;
    private int progress = 0;//上传图片进度
    private IUploadPresenter presenter_upload;

    int feedType = 1;//1文字2图片3声音

    //附件原路径
    private String img_path;

    private Boolean isFile = false;
    //上传的附件
    ArrayList<MailFileDataBean> mailFileDataBeans = new ArrayList<MailFileDataBean>();
    MailFileAdapter fileAdapter;
    UploadDialog uploadDialog;

    private DoubleSureDialog dialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_thingsfeedback);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        uploadDialog = new UploadDialog(this);
        taskMainBean = (TaskMainBean) getIntent().getExtras().getSerializable("taskMainBean");
        taskid = taskMainBean.getTaskId();
        configid = taskMainBean.getConfigId();
        signDtlPresenter = new SignDtlPresenter(new ThingModel(), this);
        presenter = new FeedBackPresenter(new ThingModel(), this);
        flowPresenter = new FlowPresenter(new ThingModel(), this);
        presenter_upload = new UploadPresenter(new UploadModel(), this);

        if (taskMainBean.getFileStatus() != null && taskMainBean.getFileStatus().equals("1")) {
            personView.setVisibility(View.GONE);
        }

        llExtraFile.setVisibility(View.VISIBLE);
//        copeMeLl.setVisibility(View.VISIBLE);

        if (configid.equals("-999")) {
            tvFeedbackSign.setText("无");
            tvFeedbackSign.setEnabled(false);
            dtlId = "";
        }

        Map<String, String> params2 = new HashMap<>();
        params2.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params2.put("configId", configid);
        params2.put("configType", "1");
        params2.put("level", taskMainBean.getCurrentNode());
        params2.put("fromMemberId", taskMainBean.getFromId());
        presenter.getFlowMember(params2);

        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("configId", configid);
        params.put("showType", "99_99");
        signDtlPresenter.getDtlList(params);

    }

    /**
     * 白名单
     */
    private void whiteListPre() {
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        if (accountId == null) {
            accountId = usersBeans_origin.get(0).getUserId();
        }
        params.put("accountId", accountId);
        params.put("configId", configid);

        presenter.whiteList(params);
    }

    @Override
    @OnClick({R.id.back, R.id.tv_feedback_sign, R.id.tv_feedback_result, R.id.et_higher, R.id.iv_add_member, R.id.feedback_commit,
            R.id.voice_redio, R.id.write_redio, R.id.keyboard_redio, R.id.voice_play, R.id.voice_delete,
            R.id.write_preview, R.id.write_delete, R.id.select_depart, R.id.copy_me_et_person,
            R.id.copy_me_thing_iv_person_choose, R.id.ll_extra_file})
    public void onClick(final View view) {
        if (CommonUtil.isFastClick()) {
            return;
        } else {
            switch (view.getId()) {
                case R.id.back:
                    finish();
                    break;
                case R.id.tv_feedback_sign:
                    /*if (configid.equals("-999")) {
                        dtlId = "";
                    } else {
                        if (signDtlDatas.size() > 0) {
                            showTypeDialog();
                        } else {
                            new ToastDialog(aty, "该模板还未设置签字区域，请联系管理员！").show();
                        }
                    }*/

                    if (configid.equals("-999")) {
                        dtlId = "";
                    } else {
                        if (signDtlDatas.size() == 0) {
                            dtlId = "-999";
                        } else {
                            showTypeDialog();
                        }
                    }
                    break;
                case R.id.tv_feedback_result:
                    resultDialog();
                    break;
                case R.id.et_higher:
                    selectPeo();
                    break;
                case R.id.iv_add_member:
                    selectPeo();
                    break;
                case R.id.feedback_commit:
                    if ("同意".equals(tvFeedbackResult.getText().toString())) {
                        if (choose == 1) {
                            if (departmentBeans.size() > 0) {
                                prepareCommit();
                            } else {
                                doubleSure();
                            }
                        } else if (choose == 2) {
                            if (usersBeans_origin.size() > 0) {
                                prepareCommit();
                            } else {
                                doubleSure();
                            }
                        } else if (choose == 3) {
                            if (groupGroupData.size() > 0) {
                                prepareCommit();
                            } else {
                                doubleSure();
                            }
                        }
                    } else {
                        prepareCommit();
                    }
                    break;
                case R.id.voice_redio:
                    feedType = 3;
                    etComment.setVisibility(View.GONE);
                    voiceRedio.setChecked(true);
                    voiceDialog();
                    break;
                case R.id.write_redio:
                    feedType = 2;
                    etComment.setVisibility(View.GONE);
                    writeRedio.setChecked(true);
                    WriteDialog dialog = new WriteDialog(aty).builder();
                    dialog.setCallBack(new WriteDialog.ICallBack() {
                        @Override
                        public void callback(File tempFile) {
                            save(tempFile);
                        }
                    });
                    break;
                case R.id.keyboard_redio:
                    feedType = 1;
                    etComment.setVisibility(View.VISIBLE);
                    keyboardRedio.setChecked(true);
                    break;
                case R.id.voice_play:
                    feedType = 3;
                    if (goOrPause == 0) {
                        playUtil = new VoicePlayUtil(recorderFile, voiceTime, voiceFirst, voiceSecend);
                        playUtil.play();
                        goOrPause = 1;
                    } else if (goOrPause == 1 || goOrPause == 2) {
                        playUtil.pause();
                        goOrPause = 0;
                    }
                    break;
                case R.id.voice_delete:
                    recorderFile = null;
                    rFileUrl = null;
                    icVoiceShow.setVisibility(View.GONE);
                    break;
                case R.id.write_preview:
                    viewDialog = new ViewShowDialog(aty, writeFile);
                    viewDialog.show();
                    break;
                case R.id.write_delete:
                    writeFile = null;
                    wFileUrl = null;
                    icWriteShow.setVisibility(View.GONE);
                    break;
                case R.id.select_depart:
                    selectDialog();
                    break;
                case R.id.copy_me_et_person:
                    selectCopy();
                    break;
                case R.id.copy_me_thing_iv_person_choose:
                    selectCopy();
                    break;
                case R.id.ll_extra_file:
                    select_file();
                    break;
            }
        }
    }

    private void doubleSure() {
        dialog = new DoubleSureDialog(this);
        dialog.builder()
                .setCallBack(new DoubleSureDialog.ICallBack() {
                    @Override
                    public void cancelCallback() {
                        dialog.dismiss();
                    }

                    @Override
                    public void sureCallback() {
                        prepareCommit();
                        dialog.dismiss();
                    }
                });
        dialog.show();
    }

    private void prepareCommit() {
        if (tvFeedbackSign.getText().toString().isEmpty()) {
            new ToastDialog(aty, "请选择签字区域").show();
        } else {
            if (tvFeedbackResult.getText().toString().length() > 0) {
                if ("同意".equals(tvFeedbackResult.getText().toString()) && choose == 2) {
                    if (memberData != null) {
                        commit();
                    } else {
                        if (usersBeans_origin.size() > 0) {
                            whiteListPre();
                        } else {
                            commit();
                        }
                    }
                } else {
                    if (etComment.getText().toString().isEmpty()) {
                        ViewInject.toast("请填写处理意见");
                    } else {
                        commit();
                    }
                }
            } else {
                ViewInject.toast("请选择审批结果");
            }
        }
    }

    /**
     * 从设备读取文件
     */
    private void select_file() {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");//设置类型，我这里是任意类型，任意后缀的可以这样写。
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(intent, 1);
    }

    private void commit() {
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("taskId", taskid);
        params.put("dtlName", tvFeedbackSign.getText().toString());
        params.put("dtlId", dtlId);
        if (feedType == 1) {
            if (!etComment.getText().toString().isEmpty()) {
                params.put("feedback", etComment.getText().toString());
            } else {
                params.put("feedback", "");
            }
        } else if (feedType == 2) {
            if (wFileUrl != null) {
                params.put("signPic", wFileUrl);
            } else {
                params.put("feedback", "");
            }
        } else if (feedType == 3) {
            if (rFileUrl != null) {
                params.put("feedVoice", rFileUrl + "/" + voicetime);
            } else {
                params.put("feedback", "");
            }
        } else {
            params.put("feedback", "");
        }
        if ("同意".equals(tvFeedbackResult.getText().toString())) {
            params.put("auditStatus", "1");
            if (choose == 1) {
                params.put("toType", "2");
                if (departmentBeans.size() > 0) {
                    params.put("toId", departmentBeans.get(0).getDepartment_id() + "");
                    params.put("toName", departmentBeans.get(0).getDepartment_name());
                }
            } else if (choose == 2) {
                params.put("toType", "1");
                if (usersBeans_origin.size() > 0) {
                    params.put("toId", usersBeans_origin.get(0).getUserId());
                    params.put("toName", usersBeans_origin.get(0).getUserName());
                }
            } else if (choose == 3) {
                params.put("toType", "3");
                if (groupGroupData.size() > 0) {
                    params.put("toId", groupGroupData.get(0).getGroupId());
                    params.put("toName", groupGroupData.get(0).getTitle());
                }
            }
        } else if ("拒绝".equals(tvFeedbackResult.getText().toString())) {
            params.put("auditStatus", "-1");
        } else if ("退回".equals(tvFeedbackResult.getText().toString())) {
            params.put("auditStatus", "2");
        }
        String copyName = "", copyId = "";
        for (int i = 0; i < usersBeans_origin_copy.size(); i++) {
            if (copyName.length() == 0) {
                copyName = usersBeans_origin_copy.get(i).getUserName();
            } else {
                copyName = copyName + ";" + usersBeans_origin_copy.get(i).getUserName();
            }
            if (copyId.length() == 0) {
                copyId = usersBeans_origin_copy.get(i).getUserId();
            } else {
                copyId = copyId + ";" + usersBeans_origin_copy.get(i).getUserId();
            }
        }
        params.put("carbonNames", copyName);
        params.put("carbonIds", copyId);
        String fileUrl = "";
        if (mailFileDataBeans.size() > 0) {
            for (int i = 0; i < mailFileDataBeans.size(); i++) {
                if (fileUrl.length() == 0) {
                    fileUrl = mailFileDataBeans.get(i).getFileUuid();
                } else if (fileUrl.length() > 0) {
                    fileUrl = fileUrl + ";" + mailFileDataBeans.get(i).getFileUuid();
                }
            }
        }
        params.put("fileUrl", fileUrl);
        presenter.approvalTask(params);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode) {
            case 10000:
                usersBeans_origin = (ArrayList<People>) data.getExtras().getSerializable("persons");
                String edt = "";
                for (int i = 0; i < usersBeans_origin.size(); i++) {
                    edt = edt + " " + usersBeans_origin.get(i).getUserName();
                }
                etHigher.setText(edt);
                break;
            case 10001:
                departmentBeans = (ArrayList<ChildDepartmentsBean>) data.getExtras().getSerializable("departmentBeans");
                String dep = "";
                for (int i = 0; i < departmentBeans.size(); i++) {
                    dep = dep + " " + departmentBeans.get(i).getDepartment_name();
                }
                etHigher.setText(dep);
                break;
            case 10002:
                groupGroupData = (ArrayList<GroupGroupData>) data.getExtras().getSerializable("groups");
                String group = "";
                for (int i = 0; i < groupGroupData.size(); i++) {
                    group = group + " " + groupGroupData.get(i).getTitle();
                }
                etHigher.setText(group);
                break;
            case 20000:
                usersBeans_origin_copy = (ArrayList<People>) data.getExtras().getSerializable("persons");
                String copyPeople = "";
                for (People childDepartmentsBean : usersBeans_origin_copy) {
                    if (copyPeople.isEmpty()) {
                        copyPeople = childDepartmentsBean.getUserName();
                    } else {
                        copyPeople = copyPeople + ";" + childDepartmentsBean.getUserName();
                    }
                }
                copyMeEtPerson.setText(copyPeople);
                break;
            case Activity.RESULT_OK:
                Uri uri = data.getData();//得到uri，后面就是将uri转化成file的过程。
                img_path = GetPathFromUri4kitkat.getPath(this, uri);
                isFile = true;
                presenter_upload.uploadFile(img_path);
                break;
            default:
                break;
        }
    }

    /**
     * 选择处理意见
     */
    private void resultDialog() {
        new ActionSheetDialog(aty)
                .builder()
                .setTitle("处理意见")
                .setCancelable(false)
                .setCanceledOnTouchOutside(false)
                .addSheetItem("同意", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                tvFeedbackResult.setText("同意");
                                selectDepart.setEnabled(true);
                                ivAddMember.setEnabled(true);
                                etHigher.setEnabled(true);
                                ivAddMember.setImageResource(R.drawable.ic_task_add);
                                etHigher.setText("");
                                usersBeans_origin.clear();
                                initPerson();
                            }
                        })
                .addSheetItem("拒绝", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                tvFeedbackResult.setText("拒绝");
                                selectDepart.setEnabled(false);
                                ivAddMember.setEnabled(false);
                                etHigher.setEnabled(false);
                                ivAddMember.setImageResource(R.drawable.ic_task_add_unselect);
                                etHigher.setText("");
                                usersBeans_origin.clear();
                            }
                        })
                .addSheetItem("退回", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                tvFeedbackResult.setText("退回");
                                usersBeans_origin.clear();
                                departmentBeans.clear();
                                selectDepart.setEnabled(false);
                                ivAddMember.setEnabled(false);
                                etHigher.setEnabled(false);
                                ivAddMember.setImageResource(R.drawable.ic_task_add_unselect);
                                usersBeans_origin.clear();

                                Map<String, String> params = new HashMap<>();
                                params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
                                params.put("taskId", taskid);
                                flowPresenter.getFlowType(params);
                            }
                        }).show();
    }

    private void initPerson() {
        String edt = "";
        if (memberData != null && memberData.getToMemberType() == 1) {
            etHigher.setText(memberData.getMemberName());
            ivAddMember.setImageResource(R.drawable.ic_task_add_unselect);
            ivAddMember.setEnabled(false);
            etHigher.setEnabled(false);
            accountId = memberData.getFlowMemberId() + "";

            selectDepart.setEnabled(false);
            selectTxt.setText("个人处理");
            departorpeopletxt.setText("个人处理");
            choose = 2;

            usersBeans_origin.clear();
            People people = new People();
            people.setUserId(memberData.getMemberId() + "");
            people.setUserName(memberData.getMemberName());
            usersBeans_origin.add(people);
            edt = memberData.getMemberName();
        } else if (memberData != null && memberData.getToMemberType() == 2) {
            ivAddMember.setImageResource(R.drawable.ic_task_add_unselect);
            ivAddMember.setEnabled(false);
            etHigher.setEnabled(false);
            etHigher.setText(memberData.getMemberName());
            selectDepart.setEnabled(false);
            selectTxt.setText("部门处理");
            departorpeopletxt.setText("部门处理");
            choose = 1;

            departmentBeans.clear();
            ChildDepartmentsBean people = new ChildDepartmentsBean();
            people.setDepartment_id(memberData.getMemberId());
            people.setDepartment_name(memberData.getMemberName());
            departmentBeans.add(people);
            edt = memberData.getMemberName();
        } else if (memberData != null && memberData.getToMemberType() == 3) {
            ivAddMember.setImageResource(R.drawable.ic_task_add_unselect);
            ivAddMember.setEnabled(false);
            etHigher.setEnabled(false);
            etHigher.setText(memberData.getMemberName());
            selectDepart.setEnabled(false);
            selectTxt.setText("群组处理");
            departorpeopletxt.setText("群组处理");
            choose = 3;

            groupGroupData.clear();
            GroupGroupData groupGroup = new GroupGroupData();
            groupGroup.setGroupId(memberData.getMemberId() + "");
            groupGroup.setTitle(memberData.getMemberName());
            groupGroupData.add(groupGroup);
            edt = memberData.getMemberName();
        }

        etHigher.setText(edt);
    }

    @Override
    public void showFeedBackResulut(FeedBackResultBean feedBackResultBean) {
        if (feedBackResultBean.getStatus().equals("200")) {
            ViewInject.toast("提交成功！");
            Intent intent = new Intent();
            setResult(100, intent);
            finish();
        } else {
            ViewInject.toast(feedBackResultBean.getMessage());
        }
    }

    @Override
    public void showWhiteList(WhiteData whiteData) {
        if (whiteData.getStatus().equals("200")) {
            if (whiteData.getDatas().get(0).getMemberList().size() > 0) {
                for (WhiteBean.MemberListEntity memberListEntity : whiteData.getDatas().get(0).getMemberList()) {
                    if (memberListEntity.getAccountId().equals(PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.USER_ID))) {
                        isSent = true;
                        break;
                    }
                }
            } else {
                isSent = true;
            }

            if (isSent) {
                commit();
            } else {
                ViewInject.toast("不在白名单中，无法流转");
            }
        } else {
            ViewInject.toast("获取白名单失败");
        }
    }

    @Override
    public void getTaskPerson(BaseEntity<FlowMemberData> taskPerson) {
        if (taskPerson.getStatus().equals("200")) {
            if (taskPerson.getDatas() != null && taskPerson.getDatas().size() > 0) {
                memberData = taskPerson.getDatas().get(0);
                initPerson();
            }
        } else {
            ViewInject.toast("获取指定人员失败");
        }
    }

    @Override
    public void getDtlList(BaseEntity<SignDtlData> taskPerson) {
        if (taskPerson.getStatus().equals("200")) {
            signDtlDatas = taskPerson.getDatas();
        }

        if (!configid.equals("-999") && signDtlDatas.size() == 0) {
            tvFeedbackSign.setText("无");
            tvFeedbackSign.setEnabled(false);
            dtlId = "-999";
        }
    }

    @Override
    public void getFlowType(BaseEntity<BackMemberData> taskPerson) {
        if (taskPerson.getStatus().equals("200")) {
            List<BackMemberData> backMemberDatas = taskPerson.getDatas();
            etHigher.setText(backMemberDatas.get(0).getMemberName());
            if (backMemberDatas.get(0).getToMemberType().equals("2")) {
                selectTxt.setText("部门处理");
                departorpeopletxt.setText("部门处理");
            } else {
                selectTxt.setText("个人处理");
                departorpeopletxt.setText("个人处理");
            }
        }
    }


    @Override
    public void uploadDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                if (isFile) {
                    uploadDialog.setCanceledOnTouchOutside(false);
                    uploadDialog.show();
                } else {
                    ViewInject.toast("正在保存图片...");
                    timerSche();
                }
                break;
            case AppConfig.DISMISS_DIALOG:
                if (isFile) {
                    uploadDialog.dismiss();
                } else {
                    ViewInject.toast("保存图片成功！");
                    progressBar.setProgress(100);
                    icTxtView.setVisibility(View.VISIBLE);
                    progressBar.setVisibility(View.GONE);
                    writeDelete.setImageResource(R.drawable.delete_icon);
                }
                break;

        }
    }

    @Override
    public void updateFile(UploadBean uploadBean) {
        if (isFile) {
            flvAttachment.setVisibility(View.VISIBLE);
            if (mailFileDataBeans.size() == 0) {
                uploadBean.getData().get(0).setFileUrl(img_path);
                mailFileDataBeans.add(uploadBean.getData().get(0));
                fileAdapter = new MailFileAdapter(this, mailFileDataBeans, true);
                flvAttachment.setAdapter(fileAdapter);
            } else {
                uploadBean.getData().get(0).setFileUrl(img_path);
                mailFileDataBeans.add(uploadBean.getData().get(0));
                fileAdapter.notifyDataSetChanged();
            }
        } else {
            MailFileDataBean mailFileDataBean = uploadBean.getData().get(0);
            wFileUrl = mailFileDataBean.getFileUuid();
        }
    }

    /**
     * 选择人员或者部门跳转界面
     */
    private void selectPeo() {
        if (choose == 1) {
            Bundle bundle = new Bundle();
            Intent intent = new Intent(this, Act_Department.class);
            bundle.putSerializable("departmentBeans", departmentBeans);
            intent.putExtras(bundle);
            aty.startActivityForResult(intent, 1);
        } else if (choose == 2) {
            Bundle bundle = new Bundle();
            Intent intent = new Intent(this, Act_Choice_Member.class);
            bundle.putSerializable("persons", usersBeans_origin);
            bundle.putString("title", "审批反馈");
            bundle.putString("type", "单选");
            intent.putExtras(bundle);
            aty.startActivityForResult(intent, 1);
        } else if (choose == 3) {
            Bundle bundle = new Bundle();
            Intent intent = new Intent(this, Act_Group.class);
            bundle.putSerializable("group", groupGroupData);
            bundle.putInt("isSelectMe", 1);
            bundle.putInt("type", 0);
            intent.putExtras(bundle);
            aty.startActivityForResult(intent, 1);
        }
    }

    /**
     * 选择签字区域
     */
    private void showTypeDialog() {
        ActionSheetDialog actionSheetDialog;
        actionSheetDialog = new ActionSheetDialog(this).builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true);

        for (int i = 0; i < signDtlDatas.size(); i++) {
            final int final1 = i;
            actionSheetDialog.addSheetItem(signDtlDatas.get(i).getDtlName(), ActionSheetDialog.SheetItemColor.Blue,
                    new ActionSheetDialog.OnSheetItemClickListener() {
                        @Override
                        public void onClick(int which) {
                            tvFeedbackSign.setText(signDtlDatas.get(final1).getDtlName());
                            dtlId = signDtlDatas.get(final1).getDtlId();

                        }
                    });
        }
        actionSheetDialog.show();
        ;
    }

    /**
     * 选择个人或者部门对话框
     */
    private void selectDialog() {
        new ActionSheetDialog(aty)
                .builder()
                .setTitle("流转类型")
                .setCancelable(false)
                .setCanceledOnTouchOutside(false)
                .addSheetItem("个人处理", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                selectTxt.setText("个人处理");
                                departorpeopletxt.setText("个人处理");
                                choose = 2;
                                String edt = "";
                                for (int i = 0; i < usersBeans_origin.size(); i++) {
                                    edt = edt + " " + usersBeans_origin.get(i).getUserName();
                                }
                                etHigher.setText(edt);
                            }
                        })
                .addSheetItem("部门处理", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                selectTxt.setText("部门处理");
                                departorpeopletxt.setText("部门处理");
                                choose = 1;
                                String edt = "";
                                for (int i = 0; i < departmentBeans.size(); i++) {
                                    edt = edt + " " + departmentBeans.get(i).getDepartment_name();
                                }
                                etHigher.setText(edt);
                            }
                        })
                .addSheetItem("群组处理", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                selectTxt.setText("群组处理");
                                departorpeopletxt.setText("群组处理");
                                choose = 3;
                                String edt = "";
                                for (int i = 0; i < groupGroupData.size(); i++) {
                                    edt = edt + " " + groupGroupData.get(i).getTitle();
                                }
                                etHigher.setText(edt);

                            }
                        }).show();

    }

    /**
     * 录音dialog
     */
    private void voiceDialog() {
        voiceDialog = new VoiceDialog(aty);
        voiceDialog.setCanceledOnTouchOutside(false);
        voiceDialog.setListener(new OnRecorderListener() {
            @Override
            public void onRecorder(File tempFile, String url) {
                if (tempFile != null) {
                    recorderFile = tempFile;
                    icVoiceShow.setVisibility(View.VISIBLE);
                    MediaPlayer mediaPlayer = new MediaPlayer();
                    try {
                        mediaPlayer.setDataSource(recorderFile.toString());
                        mediaPlayer.prepare();
                        voicetime = mediaPlayer.getDuration() / 1000;
                        voiceTime.setText(voicetime + "s");
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (url != null) {
                    rFileUrl = url;
                }
            }
        });
        voiceDialog.show();
    }

    /**
     * 得到图片路径，上传服务器
     *
     * @param tempFile
     */
    public void save(File tempFile) {
        writeFile = tempFile;
        icWriteShow.setVisibility(View.VISIBLE);
        progressBar.setMax(100);
        isFile = false;
        presenter_upload.uploadFile(tempFile.toString());
    }

    //定时器,,显示图片上传进度
    private void timerSche() {
        Timer mTimer = new Timer();
        TimerTask mTimerTask = new TimerTask() {
            @Override
            public void run() {
                while (progress < 95) {
                    progress++;
                }
                progressBar.setProgress(progress);
            }
        };
        mTimer.schedule(mTimerTask, 0, 10);
    }

    private void selectCopy() {
        Bundle bundle = new Bundle();
        Intent intent = new Intent(this, Act_Choice_Member.class);
        bundle.putSerializable("persons", usersBeans_origin_copy);
        bundle.putString("title", "新建事项");
        bundle.putString("type", "多选");
        bundle.putString("iscopy", "2");
        intent.putExtras(bundle);
        aty.startActivityForResult(intent, 1);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
